using IQIGame.Onigao.Game;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;

namespace IQIGame.Onigao.Logic
{
    /// <summary>
    /// 掉落
    /// </summary>
    public class ExecDrop : BaseServiceExecution
    {
        public override void Execute(LevelRegion region, LevelPlayer player)
        {
            ExecParamDrop config = _config as ExecParamDrop;
            if (config.cid <= 0)
            {
                LogicLog.LogError($"掉落执行id的cid参数不合法：{config.cid}");
                return;
            }
            var droppedItems = LogicDropModule.Instance.Drop(player, config.cid);
            if (droppedItems.Count > 0)
            {
                List<int> tempItems = ListPool<int>.Get();
                foreach (var rawItemData in droppedItems)
                {
                    tempItems.Add(rawItemData.cid);
                    tempItems.Add(rawItemData.num);
                }
                LogicItemModule.Instance.AddItem(player.logicPlayer, tempItems, LgLevelReasonId.Drop);
                region.NotifyDrop(player, triggerEntity, droppedItems);
                ListPool<int>.Put(tempItems);
            }
        }
    }
}
